package com.innoking.docsys.doc.controller;

import com.alibaba.fastjson.JSONObject;
import com.innoking.docsys.doc.dto.UpmsArchivesTypes;
import com.innoking.docsys.doc.dto.UpmsFondsManage;
import com.innoking.docsys.doc.module.UpmsFondsManageVO;
import com.innoking.docsys.doc.service.GetClassByFoodsService;
import com.innoking.docsys.utils.JsonToOtherUtil;
import com.innoking.docsys.utils.OtherPojo;
import com.innoking.docsys.utils.ResultObjVO;
import com.innoking.docsys.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName GetFileClassController
 * @Description 获取档案分类
 * @Author wr
 * @Date 2019/9/9 000915:16
 */
@RestController
@RequestMapping("/getClass")
public class GetFileClassController {

    Logger logger= LoggerFactory.getLogger(GetFileClassController.class);


    @Autowired
    private GetClassByFoodsService getClassByFoodsService;

    /**
     * 获取全宗ID下的所有档案分类
     * fondsCode  全宗ID
     * @return
     */
    @PostMapping("/getClassByFoods")
    @ResponseBody
    public ResultObjVO getClassByFoods(@RequestBody String data) {
        logger.info("***根据全宗ID获取档案分类进入");
        OtherPojo ob = JsonToOtherUtil.rtOtherString(data);
        String s = ob.getObj().toString();
        JSONObject jsonObject = JSONObject.parseObject(s);
        String id = jsonObject.get("id").toString();
        List<UpmsArchivesTypes> classByFoodsId = getClassByFoodsService.getClassByFoodsId(id);
        logger.info("***根据全宗ID获取档案分类结结果："+classByFoodsId.size());
        if(classByFoodsId.size() ==0){
            return ResultUtil.error("该全宗下未查询到档案分类");
        }
        //String s1 = JSON.toJSON(classByFoodsId).toString();
        return ResultUtil.success(classByFoodsId);
    }

    /**
     * 获取所有全宗
     * @return
     */
    @PostMapping("/getFoodsAll")
    @ResponseBody
    public ResultObjVO getClassByFoods() {
        logger.info("***获取所有全宗");
        List<UpmsFondsManage> fondsAll = getClassByFoodsService.getFondsAll();
        logger.info("***获取所有全宗结果："+fondsAll.size());
        if(fondsAll.size() ==0){
            return ResultUtil.error("全宗未查询到");
        }
        //String s1 = JSON.toJSON(classByFoodsId).toString();
        return ResultUtil.success(fondsAll);
    }

}
